/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.resource.service;

import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.service.CrudService;
import com.lczyfz.istep.modules.resource.dao.ResourceTrainprogramCtfsetDao;
import com.lczyfz.istep.modules.resource.entity.ResourceTrainprogram;
import com.lczyfz.istep.modules.resource.entity.ResourceTrainprogramCtfset;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 课程-课程体系中间表Service
 * @author dh
 * @version 2017-02-21
 */
@Service
@Transactional(readOnly = true)
public class ResourceTrainprogramCtfsetService extends CrudService<ResourceTrainprogramCtfsetDao, ResourceTrainprogramCtfset> {


	public ResourceTrainprogramCtfset get(String id) {
		return super.get(id);
	}
	
	public List<ResourceTrainprogramCtfset> findList(ResourceTrainprogramCtfset resourceTrainprogramCtfset) {
		return super.findList(resourceTrainprogramCtfset);
	}
	
	public Page<ResourceTrainprogramCtfset> findPage(Page<ResourceTrainprogramCtfset> page, ResourceTrainprogramCtfset resourceTrainprogramCtfset) {
		return super.findPage(page, resourceTrainprogramCtfset);
	}
	
	@Transactional(readOnly = false)
	public void save(String duallist,ResourceTrainprogram resourceTrainprogram) {
		String[] resourceCtfsetList = new String[0];
		if (duallist != null && !duallist.equals(""))
			resourceCtfsetList = duallist.split(",");
		logger.debug("length: [{}]", resourceCtfsetList.length);

		for (int i = 0; i < resourceCtfsetList.length; i++) {

			ResourceTrainprogramCtfset resourceTrainprogramCtfset=new ResourceTrainprogramCtfset();
			resourceTrainprogramCtfset.setCtfSetId(resourceCtfsetList[i]);
			resourceTrainprogramCtfset.setTrainprogramId(resourceTrainprogram.getId());
			super.save(resourceTrainprogramCtfset);
		}


	}
	@Transactional(readOnly = false)
	public void update(String duallist,ResourceTrainprogram resourceTrainprogram) {
		ResourceTrainprogramCtfset temp=new ResourceTrainprogramCtfset();
		temp.setTrainprogramId(resourceTrainprogram.getId());
		List<ResourceTrainprogramCtfset> resourceTrainprogramCtfsetList=super.findList(temp);
		for(int i=0;i<resourceTrainprogramCtfsetList.size();i++)
		{
			super.delete(resourceTrainprogramCtfsetList.get(i));
		}
		String[] resourceCtfsetList = new String[0];
		if (duallist != null && !duallist.equals(""))
			resourceCtfsetList = duallist.split(",");
		logger.debug("length: [{}]", resourceCtfsetList.length);
		for (int i = 0; i < resourceCtfsetList.length; i++) {

			ResourceTrainprogramCtfset ResourceTrainprogramCtfset=new ResourceTrainprogramCtfset();
			ResourceTrainprogramCtfset.setTrainprogramId(resourceTrainprogram.getId());
			ResourceTrainprogramCtfset.setCtfSetId(resourceCtfsetList[i]);
			super.save(ResourceTrainprogramCtfset);
		}
	}
	@Transactional(readOnly = false)
	public void delete(ResourceTrainprogramCtfset ResourceTrainprogramCtfset) {
		super.delete(ResourceTrainprogramCtfset);
	}
	
}